﻿// -----------------------------------------------------------------------
// <copyright file="ReaderWriterLockSlimExtensions.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.Threading;
namespace Rosieks.Web.Flow.Internals
{

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    internal static class ReaderWriterLockSlimExtensions
    {
        public static IDisposable BeginEnterReadLock(this ReaderWriterLockSlim @lock)
        {
            @lock.EnterReadLock();

            return new DisposeTask(() => @lock.ExitReadLock());
        }

        public static IDisposable BeginEnterWriteLock(this ReaderWriterLockSlim @lock)
        {
            @lock.EnterWriteLock();

            return new DisposeTask(() => @lock.ExitWriteLock());
        }

        public static IDisposable BeginEnterUpgradeableReadLock(this ReaderWriterLockSlim @lock)
        {
            @lock.EnterUpgradeableReadLock();

            return new DisposeTask(() => @lock.ExitUpgradeableReadLock());
        }
    }
}
